;;;"Display Text Found by Search" dialog.
;;;
;;;
;;;	AUTHOR: HENRY C. FRANCIS
;;;		425 N. Ashe Street
;		Southern Pines, NC 28387
;              
;;;		All rights reserved without prejudice.
;;;
;;;	Copyright:	12-22-97
;;;	Edited:		12-22-97
;;;
(defun c:srcht ( )
  (text_list)
  (setq num (load_dialog "srcht"))
  (new_dialog "srcht" num)
  (mode_tile "found_list" 2)
  (action_tile "found_list" "(setq cur_ndx(get_tile \"found_list\"))(set_tile \"edit_str\"(nth (atoi cur_ndx) tx_list))")
  (action_tile "edit_str" "(setq new_str (get_tile \"edit_str\"))")
  (action_tile "mod_text" "(done_dialog 2)(setq do_this T)")
  (action_tile "del_text" "(done_dialog 2)(setq do_this nil tx_list nil)(del_text)")
  (action_tile "cancel" "(setq do_this nil)(done_dialog)")
  (start_list "found_list")
  (mapcar 'add_list tx_list)
  (end_list)
  (start_dialog)
  (unload_dialog num)
  (if do_this
    (text_mod)
  )
  (princ)
);defun
(defun text_list ( )
  (if ustr nil (load "ustr" "\nFile USTR.LSP not loaded! "))
  (if do_this
    (setq tx_list nil)
    (setq tx_list nil
          chstr (ustr 1 "String to search for" chstr T)
          otstr (ustr 0 "Additional selection filter (exact match, wildcards ok)" nil T)
          count 0
          srchlst (if (and otstr (/= otstr ""))
                    (list
                      (cons -4 "<AND")
                      (cons 0 "TEXT")
                      (cons 1 (strcat "*" chstr "*"))
                      (cons 1 otstr)
                      (cons -4 "AND>")
                    )   
                    (list
                      (cons -4 "<AND")
                      (cons 0 "TEXT")
                      (cons 1 (strcat "*" chstr "*"))
                      (cons -4 "AND>")
                    )   
                  )
    )
  )
  (setq tset (ssget "X" srchlst))
  (if tset
    (setq sslen (sslength tset)
          count 0
    )
    (setq tx_list (list "*** NONE FOUND ***"))
  )
  (while (and(< count sslen)tset)
    (setq curent (entget(ssname tset count))
          curstr (cdr(assoc 1 curent))
    )
    (if tx_list
      (setq tx_list (append tx_list (list curstr)))
      (setq tx_list (list curstr))
    )
    (setq count (1+ count))
  )
;  (setq tx_list (acad_strlsort tx_list))
)
(defun text_mod ()
  (setq newent (subst
                 (cons 1 new_str)
                 (assoc 1 (entget(ssname tset (atoi cur_ndx))))
                 (entget(ssname tset (atoi cur_ndx)))
               )
  )
  (entmod newent)
;  (setq do_this nil)
  (princ)
)
(defun del_text ()
  (setq ename_list nil)
  (if tset
    (setq sslen (sslength tset)
          count 0
    )
  )
  (while (and(< count sslen)tset)
    (setq cur_ename (ssname tset count))
    (if ename_list
      (setq ename_list (append ename_list (list cur_ename)))
      (setq ename_list (list cur_ename))
    )
    (setq count (1+ count))
  )
  (foreach n ename_list (entdel n))
)